package db

import (
	"time"
)

type DbAccount struct {
	Uid          uint32    `gorm:"column:id;type:bigint(20);primaryKey;autoIncrement"` // uid
	Nickname     string    `gorm:"column:nickname;type:varchar(255)"`                  // 昵称
	HeadImageUrl string    `gorm:"column:head_image_url;type:varchar(255)"`            // 头像url
	TapOpenId    string    `gorm:"column:tap_openid;type:varchar(64)"`                 // tap_openid
	Token        string    `gorm:"column:token;type:varchar(32)"`                      // 令牌
	IpAddr       string    `gorm:"column:ip_addr;type:varchar(15)"`                    // ip地址
	CreateTime   time.Time `gorm:"column:create_time;type:datetime"`                   // 创建时间
	UpdateTime   time.Time `gorm:"column:update_time;type:datetime"`                   // 更新时间
}

func (a DbAccount) TableName() string {
	return "customer"
}

func GetDbAccount(uid uint32) (*DbAccount, error) {
	dbAccount := new(DbAccount)
	err := Conn.Where("id = ?", uid).First(dbAccount).Error
	if err != nil {
		return nil, err
	}
	return dbAccount, nil
}
